package com.cs.goods.controller;

import com.cs.common.result.HttpResp;
import com.cs.common.result.ResultCode;
import com.cs.domain.entity.Goods;
import com.cs.goods.service.IGoodsService;
import com.cs.goods.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/api/goods")
public class GoodsController {
    @Autowired
    IGoodsService iGoodsService;

    /**
     *
     * @param goodsName 根据商品名搜索
     * @param goodsTypeId 根据商品类型id搜索
     * @return 商品vo列表
     */
    @GetMapping("/findGoods")
    public HttpResp findGoodsList(String goodsName, Long goodsTypeId){
        List<GoodsVo> list = iGoodsService.findGoodsVo(goodsName,goodsTypeId);
        return HttpResp.result(ResultCode.GOODS_QUERY_SUCCESS,new Date(),list);
    }

    @PostMapping("/addGoods")
    public HttpResp addGoods(Goods goods){
        iGoodsService.addGoods(goods);
        return HttpResp.result(ResultCode.GOODS_QUERY_SUCCESS, new Date(),null);
    }

    @PostMapping("/updateGoods")
    public HttpResp updateGoods(Goods goods){
        iGoodsService.updateGoods(goods);
        return HttpResp.result(ResultCode.GOODS_QUERY_SUCCESS, new Date(),null);
    }

    @GetMapping("/delGoods")
    public HttpResp delGoods(Long goodsId){
        iGoodsService.delGoods(goodsId);
        return HttpResp.result(ResultCode.GOODS_QUERY_SUCCESS, new Date(),null);
    }
}